| Conditions | 1 |
| Paths | 8 |
| Total Lines | 128 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 49 | var View = function () { |
||
| 50 | /** The row of the notification for the pending state. */ |
||
| 51 | var notificationRow = undefined; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Renders the select2 select filed inside the OCR dropdown. |
||
| 55 | * @private |
||
| 56 | */ |
||
| 57 | var renderSelectTwo = function () { |
||
| 58 | $("#ocrLanguage").select2({ |
||
| 59 | width: 'element', |
||
| 60 | placeholder: t('ocr', 'Select language'), |
||
| 61 | formatNoMatches: function () { |
||
| 62 | return t('ocr', 'No matches found.'); |
||
| 63 | } |
||
| 64 | }); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Destroys the dropdown if existing. |
||
| 69 | * @public |
||
| 70 | */ |
||
| 71 | this.destroyDropdown = function () { |
||
| 72 | if ($('#ocrDropdown').length) { |
||
| 73 | $('#ocrDropdown').detach(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Renders the dropdown with the given languages. |
||
| 79 | * @public |
||
| 80 | * @param {Array<String>} languages |
||
| 81 | */ |
||
| 82 | this.renderDropdown = function (languages) { |
||
| 83 | this.destroyDropdown(); |
||
| 84 | var template = Handlebars.compile(TEMPLATE_OCR_DROPDOWN); |
||
| 85 | return template({ languages: languages }); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Toggles the pending notification on the top of the window. |
||
| 90 | * @public |
||
| 91 | * @param {boolean} force - If new files in queue or already in the regular loop. |
||
| 92 | * @param {number} count - How much files. |
||
| 93 | */ |
||
| 94 | this.togglePendingNotification = function (force, count) { |
||
| 95 | var html; |
||
| 96 | if (force) { |
||
| 97 | html = '<span class="icon icon-loading-small ocr-row-adjustment"></span> <span>' + n('ocr', 'OCR started: %n new file in queue.', 'OCR started: %n new files in queue.', count) + '</span>'; |
||
| 98 | } else { |
||
| 99 | html = '<span class="icon icon-loading-small ocr-row-adjustment"></span> <span>' + ' ' + n('ocr', 'OCR: %n currently pending file in queue.', 'OCR: %n currently pending files in queue.', count) + '</span>'; |
||
| 100 | } |
||
| 101 | if (count > 0 || force) { |
||
| 102 | if (notificationRow !== undefined) { OC.Notification.hide(notificationRow); } |
||
| 103 | notificationRow = OC.Notification.showHtml(html); |
||
| 104 | } else { |
||
| 105 | if (notificationRow !== undefined) { |
||
| 106 | OC.Notification.hide(notificationRow); |
||
| 107 | notificationRow = undefined; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Displays an error for a given message. |
||
| 114 | * @public |
||
| 115 | * @param {String} message |
||
| 116 | */ |
||
| 117 | this.displayError = function (message) { |
||
| 118 | OC.Notification.showHtml('<div>' + message + '</div>', { timeout: 10, type: 'error' }); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Hides or shows the selected files action button in the top bar. |
||
| 123 | * @public |
||
| 124 | */ |
||
| 125 | this.toggleSelectedFilesActionButton = function (show) { |
||
| 126 | show ? $('.selectedActionsOCR').removeClass('hidden') : $('.selectedActionsOCR').addClass('hidden'); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Renders the OCR dropdown for the FileActionMenu option |
||
| 131 | * OR TopBarSelectedFilesAction button depending on a input file. |
||
| 132 | * @public |
||
| 133 | * @param file |
||
| 134 | * @param {Array<String>} languages |
||
| 135 | */ |
||
| 136 | this.renderFileAction = function (file, languages) { |
||
| 137 | var html = this.renderDropdown(languages); |
||
| 138 | file !== undefined ? $(html).appendTo($('tr').filterAttr('data-file', file).find('td.filename')) : $(html).appendTo($('tr').find('th.column-name')); |
||
| 139 | renderSelectTwo(); |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Checks if the ocrDropdown was not clicked. |
||
| 144 | * @public |
||
| 145 | * @param {Event} event |
||
| 146 | */ |
||
| 147 | this.checkClickOther = function (event) { |
||
| 148 | if (!$(event.target).closest('#ocrDropdown').length) { |
||
| 149 | this.destroyDropdown(); |
||
| 150 | return true; |
||
| 151 | } else { |
||
| 152 | return false; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Renders the selected files action button. |
||
| 158 | * @public |
||
| 159 | */ |
||
| 160 | this.renderSelectedFilesActionButton = function () { |
||
| 161 | $(TEMPLATE_OCR_SELECTED_FILE_ACTION).appendTo($('#headerName-container')); |
||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Destroys the selected files action button. |
||
| 166 | * @public |
||
| 167 | */ |
||
| 168 | this.destroySelectedFilesActionButton = function () { |
||
| 169 | $('.selectedActionsOCR').remove(); |
||
| 170 | } |
||
| 171 | |||
| 172 | this.destroy = function() { |
||
| 173 | this.destroySelectedFilesActionButton(); |
||
| 174 | this.destroyDropdown(); |
||
| 175 | } |
||
| 176 | } |
||
| 177 | |||
| 200 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.